import { _decorator, Component, Node, Vec2, Vec3 } from 'cc';
import { Battle } from '../Battle';
import { Enum_AudioClip } from '../Enum';
import { Globals } from '../Globals';
import { ResourcesUtil } from '../ResourcesUtil';
import { EnemyController } from './Enemy/EnemyController';
import { TeammateAnimInfo, TeammateAnimType, TeammateController } from './TeammateController';
const { ccclass, property } = _decorator;

@ccclass('Teammate1Controller')
export class Teammate1Controller extends TeammateController {

    async onLoad(): Promise<void> {
        this._attackAudio = await ResourcesUtil.loadAudioClip(Enum_AudioClip.yuhangyuan_fire);
        this._skillAudio = await ResourcesUtil.loadAudioClip(Enum_AudioClip.yuhangyuan_skill);
    }

    OnChildInit() {
        let info = new TeammateAnimInfo();
        info.animType = TeammateAnimType.Idle;
        info.isLoop = false;
        info.animName = "stand";
        info.befEffect = "";
        this.teammateAnimInfoData.push(info);

        info = new TeammateAnimInfo();
        info.animType = TeammateAnimType.Attack;
        info.isLoop = false;
        info.animName = "attack";
        info.befEffect = "Player_Bullet_1";
        info.hurt = 10;
        this.teammateAnimInfoData.push(info);

        info = new TeammateAnimInfo();
        info.animType = TeammateAnimType.Walk;
        info.isLoop = true;
        info.animName = "walk";
        this.teammateAnimInfoData.push(info);

        info = new TeammateAnimInfo();
        info.animType = TeammateAnimType.Skill;
        info.isLoop = false;
        info.animName = "skill";
        info.befEffect = "Player_Skill_1";
        info.hitEffect = "Player_Skill_1_hit";
        info.hurt = 50;
        info.effectNum = 1;
        info.attackInterval = 0.07;
        info.attackRang = 640;
        info.attackTime = 4;
        this.teammateAnimInfoData.push(info);
    }

    // /**
    // * 创建player技能(技能攻击)
    // *  */
    // StartCreatePlayerSkill() {
    //     if (this.curTeammateAnimInfo == null) {
    //         return;
    //     }
    //     if (this._audioSound && this._skillAudio) {
    //         this._audioSound.playOneShot(this._skillAudio);
    //     }
    //     this.effectAttackNodes = [];
    //     for (let index = 0; index < 4; index++) {
    //         const effectNode = Globals.getNode(this.curTeammateAnimInfo.befEffect, Battle.ContentParent);
    //         let effect = this.node.getChildByName("skillNode" + (index + 1));
    //         const result = new Vec3();
    //         Vec3.add(result, this.node.position, effect.position);
    //         effectNode.setPosition(result);
    //         this.effectAttackNodes.push(effectNode);
    //     }
    //     // 改变角色方向
    //     this.SkillAttack();
    // }

    // SkillAttack() {
    //     this.unscheduleAllCallbacks();
    //     this.scheduleOnce(function () {
    //         this.ShowSkillHitEffect();
    //     }.bind(this), 0.5);
    // }

    // ShowSkillHitEffect() {
    //     let targets = [];
    //     for (let index = 0; index < this.effectAttackNodes.length; index++) {
    //         const element = this.effectAttackNodes[index];
    //         let list = this.getAttackTargetsByNode(element,400);
    //         targets = targets.concat(list);
    //     }
    //     let animInfo = this.GetTeammateAnimInfoData(TeammateAnimType.Skill);
    //     for (let index = 0; index < targets.length; index++) {
    //         const element = targets[index];
    //         if (element) {
    //             let controller = element.getComponent(EnemyController);
    //             if (!controller.isDie) {
    //                 const hitEffect = Globals.getNode(animInfo.hitEffect, Battle.ContentParent);
    //                 if (hitEffect) {
    //                     hitEffect.setWorldPosition(element.getWorldPosition());
    //                 }
    //             }
    //         }
    //     }
    //     this.scheduleOnce(function () {
    //         for (let index = 0; index < targets.length; index++) {
    //             const element = targets[index];
    //             if (element) {
    //                 let controller = element.getComponent(EnemyController);
    //                 if (!controller.isDie) {
    //                     controller.Injured(animInfo.hurt);
    //                 }
    //             }
    //         }
    //         this.effectAttackNodes = [];
    //     }.bind(this), 0.02);
    // }


}


